package pb

func EncodeVarint(d []byte, i int, v uint64) int {
	for v >= 0x80 {
		d[i] = byte(v) | 0x80
		v >>= 7
		i++
	}
	d[i] = byte(v)
	return i + 1
}

func EncodeLen(x uint64) (n int) {
	switch {
	case x < 128:
		return 1
	case x < 16384:
		return 2
	case x < 2097152:
		return 3
	case x < 268435456:
		return 4
	case x < 34359738368:
		return 5
	case x < 4398046511104:
		return 6
	case x < 562949953421312:
		return 7
	case x < 72057594037927936:
		return 8
	case x < 9223372036854775808:
		return 9
	default:
		return 10
	}
}
